package jdbc.day1.demo5_连接池;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;


public class Data {
public static void main(String[] args) throws Exception{
    DruidDataSource ds=new DruidDataSource();
//        ds.setDriverClassName("com.mysql.jdbc.Driver");
//        ds.setUrl("jdbc:mysql://localhost:3306/lly");
    Properties p=new Properties();
    p.load(Data.class.getClassLoader().getResourceAsStream("driver.properties"));
    System.out.println(p);

    ds.configFromPropety(p);

    //向池子申请一个连接
    Connection con=ds.getConnection();
    PreparedStatement st=con.prepareStatement("select * from stu");
    ResultSet rs=st.executeQuery();
    while (rs.next()){
        System.out.println(rs.getInt(1)+"\t"+rs.getString("sname"));
    }

    //把连接对象放回池子
    con.close();
}
}
